//    Copyright (C) Kherty.  All rights reserved.

using System.Collections;
using System.Windows;
using System.Windows.Input;

namespace OpenLS.Spreadsheet.UI
{
    /// <summary>
    /// Interaction logic for PrintPreviewWindow.xaml
    /// </summary>
    public partial class PrintPreviewWindow
    {
        public PrintPreviewWindow()
        {
            InitializeComponent();
        }

        public PrintPreviewWindow(Worksheet worksheet)
        {
            InitializeComponent();
            DataContext = Enumerable.ToList(
    (WorksheetPaginator.GetPaginator(worksheet)).GetPages());
            SpreadsheetElement.SetWorksheet(this, worksheet);

        }
        private void OnPageSetup(object sender, ExecutedRoutedEventArgs e)
        {
            Worksheet worksheet = SpreadsheetElement.GetWorksheet(sender);

            var window = new PageSetupWindow();
            PropertyHelper.TransferProperties((DependencyObject)sender, window);
            
            // TODO SJE: REPAIR
            // window.DataContext = worksheet.PageSetup;
            window.ShowDialog();
        }
        private void onSetPageMargins(object sender, ExecutedRoutedEventArgs e)
        {
            FrameworkElement element = (FrameworkElement)sender;
            foreach (var aPage in ((IEnumerable)element.DataContext))
            {
                if (aPage is OpenLS.Spreadsheet.UI.WorksheetPage)
                {
                    ((OpenLS.Spreadsheet.UI.WorksheetPage)aPage).Worksheet.PageMargins = (PageMargins)e.Parameter;
                }
            }
            
        }

       

    }
}
